using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using NetProtocol.POD;
using System;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_SettlementHero : UIBaseNode
    {
        #region Template Generate,don't modify

        protected partial class UIB_UISettlementHero
        {
            #region ObjectBinding Generate
            public UnityEngine.GameObject dead { protected set; get; }
            public IQIGame.Onigao.Framework.ExImage hPimageBar { protected set; get; }
            public IQIGame.Onigao.Framework.ExImage sPimageBar { protected set; get; }
            public UnityEngine.GameObject common_HeroHead { protected set; get; }
            public UnityEngine.GameObject mvp { protected set; get; }
            public UnityEngine.GameObject damage { protected set; get; }
            public UnityEngine.GameObject hurt { protected set; get; }
            public UnityEngine.GameObject cure { protected set; get; }
            public IQIGame.Onigao.Framework.ExImage imageIcon { protected set; get; }
            public IQIGame.Onigao.Framework.ExArtSpriteNum classTypeIcon { protected set; get; }
            public IQIGame.Onigao.Framework.ExArtSpriteNum attributeTypeIcon { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<UnityEngine.GameObject>("dead", out var __tbv0);
                this.dead = __tbv0;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExImage>("hPimageBar", out var __tbv1);
                this.hPimageBar = __tbv1;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExImage>("sPimageBar", out var __tbv2);
                this.sPimageBar = __tbv2;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("common_HeroHead", out var __tbv3);
                this.common_HeroHead = __tbv3;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("mvp", out var __tbv4);
                this.mvp = __tbv4;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("damage", out var __tbv5);
                this.damage = __tbv5;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("hurt", out var __tbv6);
                this.hurt = __tbv6;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("cure", out var __tbv7);
                this.cure = __tbv7;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExImage>("imageIcon", out var __tbv8);
                this.imageIcon = __tbv8;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExArtSpriteNum>("classTypeIcon", out var __tbv9);
                this.classTypeIcon = __tbv9;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExArtSpriteNum>("attributeTypeIcon", out var __tbv10);
                this.attributeTypeIcon = __tbv10;
            }
            #endregion ObjectBinding Generate
        }

        #endregion Template Generate,don't modify

        protected UIB_UISettlementHero ui { get; set; }

        // private UIN_CommonHeroHead _heroHead;
        private UIN_BattleStatInfo _damageStat;
        private UIN_BattleStatInfo _hurtStat;
        private UIN_BattleStatInfo _cureStat;

        protected override void BeforeInit()
        {
            ui = new UIB_UISettlementHero();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            this._damageStat = this.InitChildNode<UIN_BattleStatInfo>(this.ui.damage);
            this._hurtStat = this.InitChildNode<UIN_BattleStatInfo>(this.ui.hurt);
            this._cureStat = this.InitChildNode<UIN_BattleStatInfo>(this.ui.cure);
        }

        public void Initialize(BattleStatisticsUnitPOD statistics, int maxDamage, int maxHurt, int maxCure)
        {
            var rUnitStat = statistics;
            var rHeroConfig = TableCenter.hero.Get(rUnitStat.cid);
            var nSkinID = rUnitStat.skinCid;
            if (nSkinID == 0)
            {
                nSkinID = rHeroConfig.HeroSkinIds[0];
            }
            var rSkinConfig = TableCenter.heroSkin.Get(nSkinID);
            var nClass = rHeroConfig.HeroClass;
            var nElement = rHeroConfig.HeroElementType;
            var rIcon = rSkinConfig.BattleHeadIcon_fullPath;
            this.ui.classTypeIcon.SetInt(nClass);
            this.ui.attributeTypeIcon.SetInt(nElement);
            this.SetImageSprite(this.ui.imageIcon, rIcon);

            // 属性，死亡与mvp标签
            var nHp = rUnitStat.hp;
            var nMaxHp = rUnitStat.maxHp;
            var nSp = rUnitStat.sp;
            var nMaxSp = rUnitStat.maxSp;
            this.ui.dead.SetActive(nHp <= 0);
            this.ui.hPimageBar.fillAmount = nHp / (float)nMaxHp;
            this.ui.sPimageBar.fillAmount = nSp / (float)nMaxSp;
            this.ui.mvp.SetActive(rUnitStat.isMvp);

            // 统计
            this._damageStat.SetValue(rUnitStat.damage / Math.Max(1f, maxDamage), rUnitStat.damage);
            this._hurtStat.SetValue(rUnitStat.hurt / Math.Max(1f, maxHurt), rUnitStat.hurt);
            this._cureStat.SetValue(rUnitStat.cure / Math.Max(1f, maxCure), rUnitStat.cure);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        protected override void OnDispose()
        {
        }
    }
}
